package cn.fintecher.pangolin.service.business.model.request;

import cn.fintecher.pangolin.entity.mysql.QAssistCase;
import cn.fintecher.pangolin.entity.mysql.QCaseInfo;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

@Data
public class CaseCollectionStatusRequest {

    @ApiModelProperty("委托方id")
    private String principalId;

    @ApiModelProperty("批次号")
    private String batchNumber;

    @ApiModelProperty("客户姓名")
    private String personalName;

    @ApiModelProperty(notes = "案件池类别 INNEER、LEAVE_CASE、ASSIST_CASE")
    private String casePool;

    public BooleanBuilder generateQueryBuilder() {
        BooleanBuilder booleanBuilder ;
        if(Objects.equals("ASSIST_CASE",this.casePool)){
            booleanBuilder = generateAssistCaseBuilder();
        }else{
            booleanBuilder = generateCaseBuilder();
        }
        return booleanBuilder;
    }

    private BooleanBuilder generateCaseBuilder() {
        BooleanBuilder booleanBuilder = new BooleanBuilder();
        QCaseInfo qCaseInfo = QCaseInfo.caseInfo;
        if (Objects.nonNull(this.principalId)) {
            booleanBuilder.and(qCaseInfo.principalId.eq(this.principalId));
        }
        if (Objects.nonNull(this.batchNumber)) {
            booleanBuilder.and(qCaseInfo.batchNumber.like(StringUtils.join("%", this.batchNumber, "%")));
        }
        if (Objects.nonNull(this.personalName)) {
            booleanBuilder.and(qCaseInfo.personalName.like(StringUtils.join("%", this.personalName, "%")));
        }
        return booleanBuilder;
    }
    private BooleanBuilder generateAssistCaseBuilder() {
        BooleanBuilder booleanBuilder = new BooleanBuilder();
        if(Objects.nonNull(this.principalId)){
            booleanBuilder.and(QAssistCase.assistCase.principalId.eq(this.principalId));
        }
        if (Objects.nonNull(this.batchNumber)) {
            booleanBuilder.and(QAssistCase.assistCase.batchNumber.eq(this.batchNumber));
        }
        if (Objects.nonNull(this.personalName)) {
            booleanBuilder.and(QAssistCase.assistCase.personalName.eq(this.personalName));
        }
        return booleanBuilder;
    }
}
